package com.qinggeng.framework.config.mq.impl;

import com.alibaba.fastjson.JSON;
import com.qinggeng.framework.config.mq.dto.MessageOrdersDTO;
import com.qinggeng.framework.config.mq.handle.MessageHandle;
import com.qinggeng.project.system.domain.Orders;
import com.qinggeng.project.system.service.IOrdersService;
import com.qinggeng.project.system.service.IUserGoodsLimitRecordService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class UserGoodsLimitRecordHandleImpl implements MessageHandle {
    @Autowired
    private IUserGoodsLimitRecordService userGoodsLimitRecordService;
    @Autowired
    private IOrdersService ordersService;

    @Override
    public void handle(String msg) {

        log.info("限购商品购买记录处理{}",msg);

        MessageOrdersDTO ordersDTO= JSON.parseObject(msg,MessageOrdersDTO.class);
        Orders orders=ordersService.selectOrdersByOrdersNo(ordersDTO.getOrdersNo());
        if(null==orders){
            return;
        }
        try{
            //批量插入订单中的限购商品购买记录
            int rows=userGoodsLimitRecordService.insertUserGoodsLimitRecord(orders);

            log.info("添加"+rows+"条限购商品购买记录");
        }catch (Exception e){
            log.error(e.getMessage());
        }
    }
}
